package com.example.server.web.controller;

import com.example.server.web.domain.RespBean;
import com.example.server.web.domain.dto.RuleFullDto;
import com.example.server.web.service.RService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@Slf4j
@RestController
@RequestMapping("/R")
@Api(tags = {"数据挖掘"})
public class RController {

    @Autowired
    private RService rService;

    @ApiOperation("根据学年生成规则")
    @GetMapping("/getRule/{year}")
    public RespBean getRuleByYear(@PathVariable("year") String year){
        if(StringUtils.isBlank(year)){
            return RespBean.error("学年不能为空");
        }
        // 生成CSV文件
        rService.generateCsv(year);
        // 生成规则
        RuleFullDto ruleFull = rService.getRuleFull(year);
        return RespBean.success("规则生成成功",ruleFull);
    }
    @ApiOperation("根据学年生成CSV")
    @GetMapping("/getCsv/{year}")
    public RespBean queryByAcademyId(@PathVariable("year") String year) {
        rService.generateCsv(year);
        return  RespBean.success("生成CSV成功",year);
    }


}
